/**
 * 3
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-3 下午3:25
 */

#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<unordered_map<int, int>> cnts(n);
    vector<unordered_map<int, int>> f(n);
    for (int i = 0; i < n; ++i) {
        int tmp = a[i];
        int cnt = 0;
        while (tmp > 0) {
            cnts[i][tmp] = cnt;
            cnt++;
            tmp /= 2;
        }
        tmp = a[i];
        cnt = 0;
        while (tmp <= 0x3f3f3f3f) {
            cnts[i][tmp] = cnt;
            cnt++;
            tmp *= 2;
        }
    }

    for (auto value: cnts[0]) {
        f[0][value.first] = value.second;
    }

    for (int i = 1; i < n; ++i) {
        for (auto value: cnts[i]) {
            f[i][value.first] = 0x3f3f3f3f;
            for (auto map: f[i - 1]) {
                if (map.first <= value.first) {
                    f[i][value.first] = min(f[i][value.first], map.second + value.second);
                }
            }
        }
    }

    int res = 0x3f3f3f3f;

    for (auto map: f[n - 1]) {
        res = min(res, map.second);
    }

    cout << res << endl;

    return 0;
}